package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ExpertBean;
import com.project.service.ExpertService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 专家
 */
@Controller
@RequestMapping("expert")
public class ExpertController {


    @Resource
    private ExpertService expertService;


    /**
     * 显示所有专家信息
     * @param pageNO
     * @param pageSize
     * @return
     */
    @RequestMapping("findAllExpert")
    @ResponseBody
    public IPage<ExpertBean> findAllExpert(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                           @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return expertService.findAllExpert(pageNO, pageSize);
    }


    //添加专家
    @RequestMapping("addExpert")
    @ResponseBody
    public String addExpert(ExpertBean expertBean) {
        expertService.addExpert(expertBean);
        return "添加成功";
    }


    /**
     * 查看详细信息
     * @param expertId
     * @return
     */
    @RequestMapping("findId")
    @ResponseBody
    public ExpertBean findId(int expertId) {
        return expertService.findId(expertId);
    }


    /**
     * 修改信息
     * @param expertId
     * @param expertTel
     * @param expertJop
     * @param expertUnit
     * @param expertEmail
     * @return
     */
    @RequestMapping("updateExpert")
    @ResponseBody
    public String updateExpert(int expertId,String expertTel, String expertJop,
                               String expertUnit, String expertEmail) {
        expertService.updateExpert(expertId, expertTel, expertJop, expertUnit, expertEmail);
        return "修改成功";
    }


    /**
     * 删除信息
     * @param expertId
     * @return
     */
    @RequestMapping("delExpert")
    @ResponseBody
    public String delExpert(int expertId) {
        expertService.delExpert(expertId);
        return "删除成功";
    }


    /**
     * 模糊查询
     * @param pageNO
     * @param pageSize
     * @param expertName
     * @param expertSpecialty
     * @param expertUnit
     * @return
     */
    @RequestMapping("findName")
    @ResponseBody
    public IPage<ExpertBean> findName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                      @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                      String expertName, String expertSpecialty,
                                      String expertUnit) {
        return expertService.findName(pageNO, pageSize, expertName, expertSpecialty, expertUnit);
    }

}
